package com.hl.controller;

import com.hl.domain.Test1;
import com.hl.service.TestService;
import com.hl.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private TestService testService;

    @GetMapping("/findAll")
    public R findAll(){
        return R.success(testService.findAll());
    }

    @PutMapping("/update")
    public R update(Test1 test){
        return R.success(testService.update(test));
    }

    @PostMapping("/add")
    public R insert(Test1 test){
        int i = 0;
        i = testService.insert(test);
        if (i == 1){
            System.out.println("新增成功！");
            return R.success(i);
        }else {
            System.out.println("新增失败");
            return R.fail(i);
        }
    }
    @DeleteMapping("/del")
    public R del(int id) {
        int i = 0;
        i = testService.del(id);
        if (i == 1) {
            System.out.println("删除成功！");
            return R.success(i);
        } else {
            System.out.println("删除失败");
            return R.fail(i);
        }
    }

    @GetMapping("/findLike")
    public R findLike(String name){
        return R.success(testService.findLike(name));
    }
}
